home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.4 Applications 1997 August / SGI IRIX 6.4 Applications 1997 August.iso / dist / mmailp.idb / usr / lib / Zmail / bin / mailserver.z / mailserver
Encoding:
Text File  |  1997-01-22  |  4.0 KB  |  153 lines

  1. #!/bin/csh -fb
  2. # (The "-fb" might need to be changed to "-f" on some systems)
  3. #
  4. # Mailserver -- a simple MIME mailserver script.
  5. # Makes all files under a tree available for MIME-based retrieval.
  6. # By default, it sends them as the MIME type "application/octet-stream"
  7. # However, for a file named "x/y/foo.bar", you can specify a "right"
  8. # MIME content-type by putting it in the file "x/y/foo.bar.ct".
  9.  
  10. # In a distributed sendmail environment, this script can be installed with lines
  11. #    somewhat like the following two in /usr/lib/aliases:
  12. # mail-server: local-mail-server@some-single-machine
  13. # local-mail-server: "|/full/path/to/mailserver"
  14.  
  15. # By default the program uses "mail-server" as its local return address.
  16. #   and makes available all files under /usr/spool/ftp.
  17. # You might need or want to change the following parameters:
  18. set LOCALADDR=mail-server
  19. set ROOTDIR=/usr/spool/ftp
  20. set MAINTAINER=postmaster
  21. set METAMAILDIR=/usr/local/bin
  22. set LOGADDR=andrew@thumper.bellcore.com
  23. # If LOGADDR is the empty string, no logging is done.
  24. #
  25. # The real program begins here.
  26.  
  27. setenv PATH ${METAMAILDIR}:${PATH}
  28. rehash
  29. set FromName=""
  30. set Subject=""
  31. set TmpFile=/tmp/ms.$$
  32. set FOORAW=$<
  33. while ("$FOORAW" != "") 
  34. set FOO=(` echo "$FOORAW" | tr "[" "x"`)
  35. set BAR=($FOO)
  36. set BARLC=(`echo $FOO | tr A-Z a-z`)
  37. if ($BARLC[1] == "from:") then
  38.     if ("$FromName" == "") then
  39.         set FromName = ($BAR[2-])
  40.     endif
  41. else if ($BARLC[1] == "reply-to:") then
  42.     set FromName = ($BAR[2-])
  43. else if ($BARLC[1] == "subject:") then
  44.     set Subject = ($BAR[2-])
  45. endif
  46. set FOORAW=$<
  47. end
  48. # Now, stdin just has the body left, to do with as we please.
  49. # We choose to interpret the first line as the request, nothing more
  50. if ("$Subject" == "") then
  51.     set Subject=$<
  52. endif
  53.  
  54. if ("$FromName" == "") then
  55.     cat > $TmpFile <<!
  56. From: $LOCALADDR@`hostname`
  57. To: $MAINTAINER
  58. Subject: $Subject
  59.  
  60. The metamail mailserver script, installed locally as $LOCALADDR, has received a request without any reply address.
  61.  
  62. It is possible that this is the result of a user running the "mailserver" 
  63. program by hand.  It is intended to be run as an automated recipient of 
  64. mail requests, rather than an interactive program.
  65.  
  66. No reply is being generated, but the contents of the request are 
  67. reproduced below.  If no message appears below, then this program was 
  68. probably run in some circumstance other than mail delivery.
  69. --------------------
  70. !
  71.     cat $TmpFile - | /usr/lib/sendmail $MAINTAINER
  72.     # Takes the rest of the message from standard input
  73.     rm $TmpFile
  74.     exit 0
  75. endif
  76.  
  77. set danger=`echo $Subject | fgrep ..`
  78. if ($danger != "") then
  79.     cat > $TmpFile <<!
  80. From: $LOCALADDR@`hostname`
  81. To: $FromName
  82. Subject: Re: $Subject
  83.  
  84. For security reasons, this mailserver automatically rejects all requests 
  85. that contain ".." in the path name.
  86.  
  87. The file you requested, if it exists, will not be sent to you.
  88. !
  89.     /usr/lib/sendmail -t < $TmpFile
  90.     rm $TmpFile
  91.     exit 0
  92. endif
  93.  
  94. cd $ROOTDIR
  95. if (! -e "$Subject") then
  96.     cat > $TmpFile <<!
  97. From: $LOCALADDR@`hostname`
  98. To: $FromName
  99. Subject: Re: $Subject
  100.  
  101. You recently sent mail to this mail-server requesting the file: 
  102.     $Subject
  103.  
  104. That file does not exist, so your request could not be met.
  105.  
  106. Here is a list of the currently available files:
  107. --------------------------------
  108. !
  109.     ls -R >> $TmpFile
  110.     /usr/lib/sendmail -t < $TmpFile
  111.     rm $TmpFile
  112.     exit 0
  113. endif
  114.  
  115. if (-e ${Subject}.ct) then
  116.     set ct=`cat ${Subject}.ct`
  117. else 
  118.     set ct="application/octet-stream"
  119. endif
  120.  
  121. metasend -b -t "$FromName" -f "$Subject" -m "$ct" -s "Re: $Subject"
  122. if ($status != 0) then
  123.     cat > $TmpFile <<!
  124. From: $LOCALADDR@`hostname`
  125. To: $FromName
  126. Subject: Re: $Subject
  127.  
  128. You recently sent mail to this mail-server requestion the file: 
  129.     $Subject
  130.  
  131. An unanticipated error apparently precluded delivery of the file.
  132. Please accept our apologies.
  133.  
  134. Command failed: 
  135.   metasend -b -t "$FromName" -f "$Subject" -m "$ct" -s "Re: $Subject"
  136.  
  137. !
  138.     /usr/lib/sendmail -t < $TmpFile
  139.     rm $TmpFile
  140.     exit 0
  141. endif
  142.  
  143. if ("$LOGADDR" != "") then
  144.     /usr/lib/sendmail -t <<!
  145. From: ${LOCALADDR}@`hostname`
  146. To: $LOGADDR
  147. Subject: Autosend delivery report
  148.  
  149. The file: $Subject 
  150. was sent to: $FromName
  151. !
  152. exit 0
  153.